<?php
error_reporting("E_ALL^E_NOTICE");
session_start();
include './function/Tampil2.php';
include './function/Komentar.php';
?>
<html>
    <head>
        <meta name="key/words" content="berbagi,charity,community"/>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="css/bootstrap.css">
        <link rel="stylesheet" href="style.css">
        <title>Semua Berbagi - Indonesia Charity Community</title> 
        <script type="text/javascript" src="js/jquery-2.1.1.js"></script>
    </head>
    <body onload="changePagination('0', 'first')">
        <?php
        if (isset($_SESSION['user'])) {
            $status = $_SESSION['user']['status'];
            $barang = $_GET['barang'];
        } else {
            include './masuk.php';
            exit();
        }

        $t = new Tampil2();
        $nama_barang = $t->TampilDataBarang($barang)[0];
        $deskripsi_barang = $t->TampilDataBarang($barang)[1];
        $id_pengguna = $t->TampilDataBarang($barang)[2];

        $nama_donatur = $t->TampilDataPengguna($id_pengguna)[0];
        $no_tlp_donatur = $t->TampilDataPengguna($id_pengguna)[1];
        $pin_donatur = $t->TampilDataPengguna($id_pengguna)[2];
        $alamat_donatur = $t->TampilDataPengguna($id_pengguna)[3];
        ?>
        <div class="container">
            <div class="navbar navbar-default" role="navigation">
                <div class="container-fluid">
                    <div class="navbar-header">
                        <button type="button" class="navbar-toggle collapsed togle_margin" data-toggle="collapse" data-target=".navbar-collapse"> 
                            <span class="sr-only">Toggle navigation</span>
                            <span class="icon-bar"></span> 
                            <span class="icon-bar"></span> 
                            <span class="icon-bar"></span> 
                        </button> 
                        <form class="navbar-form" role="search">
                            <div class="input-group">
                                <input type="text" class="form-control" placeholder="Search" name="text_search">
                                <div class="input-group-btn">
                                    <button class="btn btn-default buttonCari" type="submit" name="button_search"><i class="glyphicon glyphicon-search"></i></button>
                                </div>
                            </div>
                        </form>
                    </div> 
                    <div class="navbar-collapse collapse"> 
                        <ul class="nav navbar-nav navbar-right"> 
                            <li>
                                <a href="pageUser.php">|    Halaman Saya</a>
                            </li>                            
                            <li>
                                <a href="index.php">|    Beranda</a>
                            </li>
                            <li>
                                <a href="clearsession.php">|    Logout</a>
                            </li>
                        </ul>                        
                        <div class="navbar-text navbar-right">Masuk sebagai <b><?php echo '  ' . $status . '  ' ?></b></div>
                    </div> 
                </div>
            </div>

            <div class="row">
                <div class="col-lg-8 col-md-8">
                    <div class="panel panel-default">
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-7 col-md-7">
                                    <img src="http://semuaberbagi.com/imageBarang/<?php echo $barang ?>01.png" class="img-thumbnail">
                                </div>
                                <div class="col-lg-5 col-md-5"><br>
                                    <img src="http://semuaberbagi.com/imageBarang/thumb/<?php echo $barang ?>01_s2.png" class="img-thumbnail" alt="no image">
                                    <img src="http://semuaberbagi.com/imageBarang/thumb/<?php echo $barang ?>01_s3.png" class="img-thumbnail" alt="no image">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-4 col-md-4">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Biodata Donatur
                        </div>
                        <div class="panel-body">
                            <div class="row">
                                <div class="col-lg-12 col-md-12">
                                    <div class="row">
                                        <div class="col-lg-3">
                                            <b>Nama</b>
                                        </div>
                                        <div class="col-lg-1">
                                            <b>:</b>
                                        </div>
                                        <div class="col-lg-7">
                                            <?php echo $nama_donatur ?>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-3">
                                            <b>No. Telp</b>
                                        </div>
                                        <div class="col-lg-1">
                                            <b>:</b>
                                        </div>
                                        <div class="col-lg-7">
                                            <?php echo $no_tlp_donatur ?>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-3">
                                            <b>Pin BB</b>
                                        </div>
                                        <div class="col-lg-1">
                                            <b>:</b>
                                        </div>
                                        <div class="col-lg-7">
                                            <?php echo $pin_donatur ?>
                                        </div>
                                    </div>
                                    <div class="row">
                                        <div class="col-lg-3">
                                            <b>Alamat</b>
                                        </div>
                                        <div class="col-lg-1">
                                            <b>:</b>
                                        </div>
                                        <div class="col-lg-7">
                                            <?php echo $alamat_donatur ?>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-lg-8 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Deskripsi Barang
                        </div>
                        <div class="panel-body">
                            <?php echo $deskripsi_barang ?>
                        </div>
                    </div>
                </div>
            </div>       
            <script>
                $(document).ready(function () {
                    $('#komentar').keyup(function (e)
                    {
                        if (e.keyCode == 13)
                        {
                            var komentar = $('#komentar').val();
                            var id_user = $('#id_user').val();
                            var id_barang = $('#id_barang').val();
                            var nama = $('#nama').val();
                            var foto = $('#foto').val();
                            if (komentar == "")
                            {
                                alert("tuliskan komentar anda");
                            }
                            else
                            {
                                $("#listkomentar").append("<div class=\"row\"><div class=\"col-lg-4\"><image class=\"img-responsive img-circle\" src=\"" + foto + "\"/></div><div class=\"col-lg-8\"><span><b> " + nama + " </b><br/> " + komentar + " </span></div></div>");
                                $.post("deskripsiBarang.php", {id_user: id_user, komentar: komentar, id_barang: id_barang, nama: nama, foto: foto}, function (data)
                                {
                                });
                                $('#komentar').val("");
                            }
                        }
                    });
                });
            </script>
            <?php
            if ($_POST) {
                $komentar = $_POST['komentar'];
                $barang1 = $_POST['id_barang'];
                $pengguna1 = $_POST['id_user'];
                $komentar1 = new Komentar();
                $komentar1->setId_Barang($barang1);
                $komentar1->setId_Pengguna($pengguna1);
                $komentar1->setKomentar($komentar);
                $komentar1->insertKomentar();
            }
            ?>
            <div class="row">
                <div class="col-lg-8 col-md-12">
                    <div class="panel panel-default">
                        <div class="panel-heading">
                            Komentar
                        </div>
                        <div class="panel-body">
                            <div class="panel panel-primary">
                                <div class="panel-body">
                                    <input type="hidden" name="id_user" id="id_user" value="<?php echo $t->getIdPengguna($status) ?>"/>
                                    <input type="hidden" name="nama" id="nama" value="<?php echo $t->getNamaPengguna($t->getIdPengguna($status)) ?>"/>
                                    <input type="hidden" name="foto" id="foto" value="<?php echo $t->getFotoPengguna($t->getIdPengguna($status)) ?>"/>
                                    <input type="hidden" name="id_barang" id="id_barang" value="<?php echo $barang ?>"/>
                                    <input type="text" class="form-control" id="komentar" name="komentar" placeholder="Tulis Komentar ..."/>
                                    <div id="listkomentar" name="listkomentar">
                                        <?php
                                        echo $t->get5Komentar($barang);
                                        ?>
                                    </div>                                    
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="panel panel-default panelKat">
                <div class="panel-footer panelKaki">
                    <div class="row">
                        <div class="col-md-12 col-xs-12">
                            <br><br><br>
                            <center><label class="fontKaki"><h4>@ Copyright 2014 semua berbagi - All right reserved</h4></label></center>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </body>
</html>
